package com.waters321.rock.orm.entity;

import java.io.Serializable;
import java.util.Date;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableLogic;
import com.baomidou.mybatisplus.annotations.Version;
import com.baomidou.mybatisplus.enums.FieldFill;
import com.waters321.rock.orm.enums.DeleteFlagEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@ApiModel(value = "公共基础模型")
public class BaseEntity<M, T extends BaseEntity<M, T>> extends Model<T> {

  private static final long serialVersionUID = 4458272332994162755L;

  public static final String FIELD_ID = "id";

  public static final String FIELD_OPERATE_ID = "operate_id";

  public static final String FIELD_DELETE_FLAG = "delete_flag";

  public static final String FIELD_CREATE_AT = "create_at";

  public static final String FIELD_CREATE_BY = "create_by";

  public static final String FIELD_CREATE_BY_NAME = "create_by_name";

  public static final String FIELD_UPDATE_AT = "update_at";

  public static final String FIELD_UPDATE_BY = "update_by";

  public static final String FIELD_UPDATE_BY_NAME = "update_by_name";

  public static final String FIELD_VERSION = "version";


  public static final String ID = "id";

  public static final String OPERATE_ID = "operateId";

  public static final String DELETE_FLAG = "deleteFlag";

  public static final String CREATE_AT = "createAt";

  public static final String CREATE_BY = "createBy";

  public static final String CREATE_BY_NAME = "createByName";

  public static final String UPDATE_AT = "updateAt";

  public static final String UPDATE_BY = "updateBy";

  public static final String UPDATE_BY_NAME = "updateByName";

  public static final String VERSION = "version";

  @TableId
  @ApiModelProperty(value = "主键")
  protected M id;

  @TableField(fill = FieldFill.INSERT_UPDATE)
  @ApiModelProperty(value = "操作序号")
  protected Long operateId;

  @TableLogic
  @TableField(fill = FieldFill.INSERT)
  @ApiModelProperty(value = "删除标记")
  protected DeleteFlagEnum deleteFlag;

  @JSONField(format = "yyyy-MM-dd HH:mm:ss")
  @TableField(fill = FieldFill.INSERT)
  @ApiModelProperty(value = "创建时间")
  protected Date createAt;

  @TableField(fill = FieldFill.INSERT)
  @ApiModelProperty(value = "创建人id")
  protected Long createBy;

  @TableField(fill = FieldFill.INSERT)
  @ApiModelProperty(value = "创建人姓名")
  protected String createByName;

  @JSONField(format = "yyyy-MM-dd HH:mm:ss")
  @TableField(fill = FieldFill.UPDATE)
  @ApiModelProperty(value = "更新时间")
  protected Date updateAt;

  @TableField(fill = FieldFill.UPDATE)
  @ApiModelProperty(value = "更新人id")
  protected Long updateBy;

  @TableField(fill = FieldFill.UPDATE)
  @ApiModelProperty(value = "更新人姓名")
  protected String updateByName;

  @TableField(fill = FieldFill.INSERT)
  @Version
  @ApiModelProperty(value = "乐观锁序列号")
  protected Integer version;

  @Override
  protected Serializable pkVal() {
    return (Serializable) this.id;
  }

}
